package com.game.view.component
{
	import com.dusk.util.FilterUtil;
	import com.dusk.util.ResUtil;
	import com.dusk.util.TextUtil;
	import com.greensock.TweenMax;
	
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.utils.Dictionary;
	
	public class BossBloodBar extends ComponentBase
	{
		
		public var maskLayer:MovieClip;
		
		public var nameContainer:MovieClip;
		
		public static const COLOR_WHITE:uint = 0xFFFFFF;
		
		public static const COLOR_PURPLE:uint = 0x6633CC;
		
		public static const COLOR_RED:uint = 0xCC0000;
		
		public static const COLOR_ORANGE:uint = 0xFF9933;
		
		public function BossBloodBar(name:String = "")
		{
			super();
			if(name.length)
			{
				setMonsterName(name);
			}
		}
		
		override protected function beforeAdded():void
		{
			var mc:MovieClip = ResUtil.getComponentView("BossBloodBar") as MovieClip;
			nameContainer = mc.getChildByName("nameContainer") as MovieClip;
			maskLayer = mc.getChildByName("maskLayer") as MovieClip;
			addChild(mc);
		}
		
		public function update(scale:Number):void
		{
			if(scale < 0) scale = 0;
			if(scale > 1) scale = 1;
			if(TweenMax.isTweening(maskLayer))
			{
				TweenMax.killTweensOf(maskLayer);
			}
			TweenMax.to(maskLayer,0.2,{"scaleX":scale});
		}
		
		public function setMonsterName(monsName:String, color:uint = COLOR_WHITE):void
		{
			name = monsName;
			var data:Dictionary = getNameConfig(name.length);
			var txt:TextField = TextUtil.creatTextField(name,TextUtil.BOSS_BLOOD_FONT, data.size,"center",color,false,false);
			txt.x = data.x;
			txt.y = data.y;
			nameContainer.addChild(txt);
			FilterUtil.setGlow(nameContainer,COLOR_ORANGE,0.5,4,4,1);
			FilterUtil.clearCache();
			nameContainer.cacheAsBitmap = true;
		}
		
		private function getNameConfig(length:int):Dictionary
		{
			var data:Dictionary = new Dictionary();
			switch (length)
			{
				case 1:
					data.x = -200;
					data.y = -20;
					data.size = 30;
					break;
				case 2:
					data.x = -209;
					data.y = -16;
					data.size = 25;
					break;
				case 3:
					data.x = -228;
					data.y = -15;
					data.size = 23;
					break;
				case 4:
					data.x = -232;
					data.y = -12;
					data.size = 18;
					break;
				case 5:
					data.x = -235;
					data.y = -9.5;
					data.size = 15;
					break;
				case 6:
				default:
					data.x = -232;
					data.y = -8.5;
					data.size = 12;
			}
			return data;
		}
	}
}